<template>
    <footer class="ad_wrapper" v-if="api_data.length">
      <div class="head_wrap"><i></i>其它精彩测试</div>
      <ul class="list_wrap">
        <li v-for="(i,idx) in api_data" :key="idx" @click="to_link(i.link)">
          <div class="c_img">
            <img :src="img_url(i.img)" alt="" srcset="">
            <p>2000人已测</p>
          </div>
          <div class="c_info">
            <div class="des">
              <h4>{{i.title}}</h4>
              <p>{{i.subtitle}}</p>
            </div>
            <a class="btn">去看看</a>
          </div>
        </li>
      </ul>
    </footer>
</template>
<script>
import tool from "@/assets/js/tool.js";
export default {
  watch:{
    adProp:{
      handler:function(val,oldval){
        if(val){
          this.fetch_ad();
        }
      },
      deep:true
    }
  },
  props:{
    adProp:Object,
    required: true,
  },
  data(){
    return{
      base_url:'https://ykdstatic.dd668.cn/',
      api_data:[],
    }
  },
  created(){
    this.fetch_ad();
  },
  methods:{
    img_url(url){
      return this.base_url+url;
    },
    fetch_ad(){
      var self = this;
      var param = {
        gid:self.adProp.gid,
        type:self.adProp.type,
        position:self.adProp.position 
      }
      self.$fetch.post("https://api.52dd.cn/v1/TarotDay/getadset",param).then(res =>{
         if(res.code == 1){
            self.api_data = res.data;
            console.log(self.api_data);
          }
      })
    },
    to_link(link){
      tool.createNavigation(this, "ad", link);
    }
  }
  
}
</script>
<style lang='less' scoped>
  .ad_wrapper{
    width: 100%;
    background: #f5f5f5;
    padding-bottom: 20px;
    .head_wrap{
      display: flex;
      align-items: center;
      justify-content: center;
      height: 90px;
      margin-bottom: 10px;
      background: #ffffff;
      font-size: 30px;
      i{
        display: inline-block;
        flex:0 0 43px;
        height: 43px;
        // background: url(glb_ad_icon.png) no-repeat center/100% 100%;
        background: url(../../static/image/public/glb_ad_icon.png) no-repeat center/100% 100%;
        margin-right: 20px;
      }
    }
    .list_wrap{
      li{
        background: #ffffff;
        padding: 20px;
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        .c_img{
          width: 185px;
          height: 124px;
          margin-right: 20px;
          position: relative;
          img{
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
          p{
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            font-size: 18px;
            background: rgba(0,0,0,.5);
            color: #ffffff;
            text-align: center;
            display: none;
          }
        }
        .c_info{
          flex: 1;
          display: flex;
          align-items: center;
          .des{
            flex: 1;
            margin-right: 20px;
            h4{
              font-size: 28px;
              margin-bottom: 10px;
            }
            p{
              font-size: 24px;
              color: #999999;
              overflow : hidden;
              text-overflow: ellipsis; /* text-overflow : clip;*/
              display: -webkit-box;
              -webkit-line-clamp: 2;/*此为两行，设置行数*/
              -webkit-box-orient: vertical;/*子元素垂直排列*/
            }
          }
          .btn{
            display: block;
            font-size: 24px;
            color: #DC5050;
            border: 1px solid #DC5050;/*no */
            padding: 5px 20px;
            border-radius: 25px;
          }
        }
      }
    }
  }
</style>